#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\MGT.h>



static void *storeFromStruct;

static int recordNum;
void registerMGT(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadMGTRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerMGT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(MGT_FILENAME, SIZE_MGT_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreMGTRecFromStruct(void *vdStruct)
{
	registerMGT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetMGTRec(), vdStruct, SIZE_MGT_REC);

}

void vdCopyMGTRecFromStruct(void *vdStruct)
{
	registerMGT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetMGTRec(), SIZE_MGT_REC);

}

int	inSaveMGTRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerMGT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(MGT_FILENAME, SIZE_MGT_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateMGTRecFromStruct (void *vdStruct)
{
	int inRet;

	registerMGT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(MGT_FILENAME, SIZE_MGT_REC, recordNum, (char *) vdStruct);

	return inRet;
}

char* szGetPriIPFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetPriIP();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MGT_REC*)vdStruct)->szPriIP;
}

void vdSetPriIPFromStruct(const char* szPriIP, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetPriIP(szPriIP);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((MGT_REC*)vdStruct)->szPriIP, szPriIP, sizeof(((MGT_REC*)NULL)->szPriIP)-1);
}

char* szGetSecIPFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetSecIP();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MGT_REC*)vdStruct)->szSecIP;
}

void vdSetSecIPFromStruct(const char* szSecIP, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetSecIP(szSecIP);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((MGT_REC*)vdStruct)->szSecIP, szSecIP, sizeof(((MGT_REC*)NULL)->szSecIP)-1);
}

char* szGetPriPortFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetPriPort();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MGT_REC*)vdStruct)->szPriPort;
}

void vdSetPriPortFromStruct(const char* szPriPort, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetPriPort(szPriPort);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((MGT_REC*)vdStruct)->szPriPort, szPriPort, sizeof(((MGT_REC*)NULL)->szPriPort)-1);
}

char* szGetSecPortFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetSecPort();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MGT_REC*)vdStruct)->szSecPort;
}

void vdSetSecPortFromStruct(const char* szSecPort, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetSecPort(szSecPort);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((MGT_REC*)vdStruct)->szSecPort, szSecPort, sizeof(((MGT_REC*)NULL)->szSecPort)-1);
}

